<?php
/**
 * Joomla! 1.5 component Bbits Simple directory
 *
 * @version $Id: view.html.php 2011-07-08 03:53:16 svn $
 * @author Miguel Puig
 * @URL http://miguelpuig.com
 * @package Joomla
 * @subpackage Bbits Simple directory
 * @license GNU/GPL
 *
 * Simple Directory by bittingbits.com
 *
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.model');

class BbitsdModelBbitsd extends JModel {
    var $_data;
    var $_query;
    
    function __construct()
    {
        parent::__construct();
    }
    
    function _buildQuery()
    {
        $this->_query = 'SELECT * FROM #__bbitsd_items WHERE published=1';
        return $this->_query;
    }

    
    function getData()
    {
        $this->_buildQuery();
        
        if (empty($this->_data)) {
            $this->_db->setQuery($this->_query);
            $this->_data = $this->_getList($this->_query);
        }
        
        return $this->_data;
    }
    
    function getCountries()
    {
    	$query = 'SELECT * FROM #__bbitsd_countries WHERE state=1';
    	$this->_db->setQuery($query);
    	$data = $this->_getList($query);
    	return $data;
    }
    function getTypes()
    {
    	$query = 'SELECT * FROM #__bbitsd_types WHERE state=1 ORDER BY ordering';
    	$this->_db->setQuery($query);
    	$data = $this->_getList($query);
    	return $data;
    }
    function getGroups()
    {
    	$query = 'SELECT * FROM #__bbitsd_groups WHERE state=1';
    	$this->_db->setQuery($query);
    	$data = $this->_getList($query);
    	return $data;
    }
    
    function getAllDataCountries()
    {
    	//Continents
    	$query = 'SELECT * FROM #__bbitsd_groups WHERE state=1 ORDER BY title';
    	$this->_db->setQuery($query);
    	$continents = $this->_getList($query);
    	
    	$c_n = 0;
		foreach ($continents as $c):
			$query = 'SELECT * FROM #__bbitsd_countries WHERE state=1 AND zone = '.$c->id.' ORDER BY title';
	    	$this->_db->setQuery($query);
	    	$continents[$c_n]->countries = $this->_getList($query);
			
		$c_n ++;	
		endforeach;
		
		return $continents;

    }
    
    function getModel()
    {
        return $this;
    }
    
    function getChilds($id)
    {
        $this->_buildQuery();
        
        return $this->_getList($this->_query);
    }
    
    function getCategory($id)
    {
        $query = 'SELECT * FROM #__joomdiet_Food_Category WHERE id='.$id;
        $this->_db->setQuery($query);
        $result = $this->_db->loadObject();
        return $result;
    }
}
?>
